<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-系统管理">
</@frame.head>
<script type="text/javascript" src="${contextPath}/resources/js/tool/ckeditor/ckeditor.js"></script>
<div class="page-container">
	<form action="${contextPath}/helpInfo/helpInfo_save" method="post" id="save_form" name="save_form">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				帮助标题：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="title" name="title" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				帮助分类：</label>
			<div class="formControls col-xs-6 col-sm-6">
			  <span class="select-box radius">
				<select class="select"  name="helpCategoryId" id="helpCategoryId">
	           	
				<#list helpCategoryMap?keys as testKey>
				<option value="${testKey}" >              	${helpCategoryMap[testKey]}
				</option>
				
				
				</#list>
	           </select>
	          </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				帮助详情：</label>
			<div class="formControls col-xs-6 col-sm-8">
             <textarea   id="content" name="detail"></textarea> 
             <script type="text/javascript">
      	        CKEDITOR.replace('content',
      	        	{
      	        	filebrowserUploadUrl : '${contextPath}/ckeditor/uploader?Type=File&uploadModel=helpInfo',
      	        	filebrowserImageUploadUrl : '${contextPath}/ckeditor/uploader?Type=Image&uploadModel=helpInfo',
      	        	filebrowserFlashUploadUrl : '${contextPath}/ckeditor/uploader?Type=Flash&uploadModel=helpInfo'
      	        	});
             </script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" type="button" onclick="save();"  value="&nbsp;&nbsp;增加&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
<@frame.end "default">
</@frame.end>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
var path="${contextPath}";



function save(){
	CKupdate();
	var name=$("#title").val();
    var helpCategory=$("#helpCategoryId").val(); 
	//验证只包含字母或者汉字
var pattern1 =/(^[\u4e00-\u9fa5A-Za-z]*$)/;

	   if(name.length==0){
		   layer.alert("请输入标题");
          document.typeForm.name.focus();
          return false;
       }
	 if (!pattern1.test(name)) {
		 layer.alert("请输入合法的标题！");
	     	   document.typeForm.name.focus();
	       	   return false;
  	   }
     	if(helpCategory==""){
     		layer.alert("请选择类型！")
     		return false;
     	}
     
		var detail =  $("textarea[name='detail']").val();
		detail = trim(detail);
		if(detail == "" || detail == null){
			alert("请填写帮助详情");
			return false;
		}
		var url =path+"/helpInfo/helpInfo_save";
		   $.ajax({
			   url : url,
		   	   type : "post",
		   	   dataType : "text",
		   	   data : {"title":name,"helpCategoryId":helpCategory,"detail":detail},
		   	   success : function(msg){
			   		  var resultArr = msg.split(",");
			   		  if(resultArr[0]=="success"){
		                    layer.msg('添加帮助信息成功!',{icon:1,time:1000},function(){
    	                        parent.window.location.reload();
    	                    });
			   		  }else{
			   			 if(resultArr[1] != null && resultArr[1] != ""){
			   				alert("发布帮助失败," + resultArr[1]);
			   			 }else{
			   				 alert("操作失败");
			   			 }
			   			
			   		  }
		   	  },
			  error : function(){
				  alert("操作失败");
			  }
		   });
}
function CKupdate() {
    for (instance in CKEDITOR.instances)
        CKEDITOR.instances[instance].updateElement();
}
function trim(str){ 
	 return str.replace(/(^\s*)|(\s*$)/g, "");
	}
</script>
</body>
</html>